package org.cos.generation.util.info;

import java.util.Hashtable;
import java.util.Set;

import org.cos.generation.epda.EPDA;
import org.cos.generation.epda.Method;
import org.eclipse.jdt.core.dom.MethodDeclaration;

public class ClassInfo {

	private String qualifiedName;
	
	private Hashtable<Method, MethodInfo> methodTable;
	
	private EPDA epda;

	public ClassInfo(String qualifiedName, MethodDeclaration[] methodList) {
		this.qualifiedName = qualifiedName;
		epda = new EPDA();
		methodTable = new Hashtable<Method, MethodInfo>();
		for (MethodDeclaration method : methodList) {
			addMethod(method, epda.newState(), epda.newState());
		}
	}
	
	public EPDA getEPDA() {
		return epda;
	}

	public MethodInfo getMethodInfo(Method method) {
		if (method != null && method.getQualifiedType().equals(qualifiedName)) {
			return methodTable.get(method);
		}
		return null;
	}
	
	private boolean addMethod(MethodDeclaration methodNode, 
			int initStateIndex,	int returnStateIndex) {
		Method customMethod = Method.valueOf(methodNode.resolveBinding());
		int paraNum = methodNode.parameters().size();
		MethodInfo methodInfo = new MethodInfo(paraNum, 
				initStateIndex, returnStateIndex);
		methodTable.put(customMethod, methodInfo);
		return true;
	}
	
	public Set<Method> getAllMethod() {
		return methodTable.keySet();
	}

	public String getQualifiedName() {
		return qualifiedName;
	}

}
